package org.geeks.gsflyingsaucer.func.flayingsaucer;

import com.lowagie.text.pdf.BaseFont;
import java.io.FileOutputStream;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.xhtmlrenderer.pdf.ITextFontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer;

@Slf4j
public class FlayingsaucerT {

  @Test
  public void createPDF() throws Exception {
    String htmlContent =
        "<html> <body style=\"font-family: SimSun;\"> <h4>你好，<span>宋骁</span></h4> <h4>Powered by Geek-S and Scott</h4> </body> </html>";

    ITextRenderer renderer = new ITextRenderer();
    ITextFontResolver iTextFontResolver = renderer.getFontResolver();

    iTextFontResolver.addFont("/fonts/simsun.ttf", BaseFont.IDENTITY_H, false);

    renderer.setDocumentFromString(htmlContent);

    renderer.layout();

    renderer.createPDF(new FileOutputStream("/tmp/test.pdf"));
  }
}
